Skip to content

Insert with specific unique constraint #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 9, 2025

Conversation

rcarver
Copy link
Contributor

@rcarver rcarver commented May 28, 2025

This adds an overload of insert where you can specify a specific unique constraint. Currently, upsert behavior is only available for primary key tables, on the primary key.

Given a table with additional unique constraint:

CREATE TABLE referenceFiles (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  corpus TEXT NOT NULL,
  filePath TEXT NOT NULL,
  UNIQUE(corpus, filePath)
) STRICT

You can upsert by specifying those columns:

ReferenceFile.insert {
  
} onConflict: {
  ($0.corpus, $0.filePath)
} doUpdate: {
  
}

@rcarver rcarver marked this pull request as draft May 28, 2025 02:41
@rcarver rcarver marked this pull request as ready for review May 28, 2025 02:49
Copy link
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcarver Thanks for this! We finally had a chance to figure out the surface area of all the changes needed and I've pushed them to your branch. Basically:

  • Update all inserts to take trailing closures for inserted records. This makes it clearer that the next trailing closure is the onConflict closure in those cases.
  • Update all existing onConflict closures to the more descriptive onConflictDoUpdate
  • Deprecate the existing insert functions in favor of the above changes.

Brandon and I will discuss the final details and hopefully merge soon!

@rcarver
Copy link
Contributor Author

rcarver commented Jun 8, 2025

@stephencelis oh nice, the consistent trailing closure syntax is great!

@stephencelis stephencelis merged commit e94783f into pointfreeco:main Jun 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants